<meta charset="utf-8">
<script type="text/javascript">
$(function(){
	initRuleList();
});
function initRuleList(){
	showLoading('正在加载...');
	$.get("{:U('Reply/queryRuleList')}?ts=" + new Date().getTime(), function (html) {
		$("#keywordSettingArea").html(html);
		// 添加规则
		$("#newRule").click(function () {
			if ($("#listItemNew").hasClass("none")) {
				$(this).html("\u653e\u5f03\u6dfb\u52a0");
				$(this).removeClass("btnGrayS").addClass("btnRed");
				$("#listItemNew .ruleName").val("");
				$("#listItemNew  .keywordItems").html("");
				$("#listItemNew  .ruleMessage").html("");
				$("#listItemNew").removeClass("none");
				$("#listItemNew .detail").show();
			} else {
				$("#listItemNew").addClass("none");
				$(this).removeClass("btnRed").addClass("btnGrayS");
				$(this).html("\u6dfb\u52a0\u89c4\u5219");
			}
		});
	 
		// 展开编辑框
		$(".unfold").click(function () {
			var parent = $(this).parentsUntil()[2];
			$(".ruleItemEditing").removeClass("ruleItemEditing");
			$(parent).addClass("ruleItemEditing");
		});
		// 收起编辑框
		$(".pickup").click(function () {
			var parent = $(this).parentsUntil()[2];
			$(parent).removeClass("ruleItemEditing");
		});
		$(".ruleMessage").each(function () {
			$(this).keyup();
		});
		//规则回复内容选项卡
		$('.role_list .chooseMedia').click(function(){
			var $this=$(this);
			$('.role_list  .selected').removeClass('selected');
			$this.addClass('selected');
			$('.role_list .panel').hide();
			$(".role_list #"+$this.attr("pane")).show();
			$this.parent().parent().find('input[name="type"]').val($this.attr('type'));
			
		});
		$(".appmsg").click(function(){
			$(".msgs .current").removeClass("current");
			$(this).addClass('current');
		});
		
		$(".addKeyword").each(function () {
			$(this).click(function () {
				var ul = $(this).parent().parent().find(".keywordItems").get(0);
				$("#context").val("").keyup();
				$("#newKeywordDialog").dialog({title:"\u6dfb\u52a0\u5173\u952e\u5b57", width:450, height:250, modal:true, position:{at:"center"}, buttons:{"\u786e\u5b9a":function () {
					var text = $("#context").val();
					var html = "<li class=\"item float-p\">";
					html += "<label class=\"left\">";
					html += "<input class=\"left\" type=\"checkbox\">";
					html += "<div class=\"val left\">" + text + "</div>";
					html += "</label>";
					html += "<a class=\"keywordEditor oh z c-opr\" onclick=\"editKeyword(this)\" >\u7f16\u8f91</a></li>";
					$(html).appendTo($(ul));
					$(this).dialog("close");
				}, "\u53d6\u6d88":function () {
					$(this).dialog("close");
				}}});
			});
		});
		$(".delKeyword").each(function () {
			$(this).click(function () {
				var ul = $(this).parent().parent().find(".keywordItems").get(0);
				$(ul).find("input[type=\"checkbox\"]").each(function () {
					if ($(this).attr("checked")) {
						$(this).parent().parent().remove();
					}
				});
			});
		});
		hideLoading();
	});
}
function editKeyword(a) {
	var ul = $(a).parent().parent();
	var text = $($(a).parent().find(".val").get(0)).text();
	$("#context").val(text).keyup();
	$("#newKeywordDialog").dialog({title:"\u7f16\u8f91\u5173\u952e\u5b57", width:450, height:250, modal:true, position:{at:"center"}, buttons:{"\u786e\u5b9a":function () {
		var text = $("#context").val();
		$(a).parent().find(".val").html(text);
		$(this).dialog("close");
	}, "\u53d6\u6d88":function () {
		$(this).dialog("close");
	}}});
}
</script>
<div class="container-fluid">
	<ol class="breadcrumb" style="margin-bottom: 0px">
		<li>
			<a href="index.do">首页</a>
		</li>
	
		<li>
			消息回复
		</li>
	</ol>
	<div>
		<div class='panel   col-md-12'>
			<div class="content smartpage">
				<div class="page-header">
					<h1>
						关键词自动回复
						<small>订阅用户发送的信息含有多个设置的关键字，则会随机回复。</small>
					</h1>
				</div>
				<div id="keywordSettingArea" class="settingArea"></div>
				<div id='newKeywordDialog' style="display: none">
					<div class='panel'>
						<div class="txtArea">
							<div class="functionBar">
								<div class="tip">
									还可以输入
									<span class="b i">600</span>字
								</div>
							</div>
							<div class="editArea">
								<textarea class='form-control'
									style="width: 100%; height: 60px; border: 1px solid #AAAAAA;"
									id='context' onkeyup="setWordsLimit(this)" maxlength='600'></textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>		
</div>
